//
//  HMRefreshControl.m
//  HMWeiBoOC
//
//  Created by GD on 16/9/27.
//  Copyright © 2016年 geduo. All rights reserved.
//

#import "HMRefreshControl.h"
#import "UILabel+HMLabel.h"
#import <Masonry.h>

//  下拉刷新控件的高度
CGFloat  HMRefreshControlHeight = 50;
//  下拉刷新控件状态
typedef enum : NSUInteger {
    HMRefreshControlStateNormal,
    HMRefreshControlStatePulling,
    HMRefreshControlStateRefreshing,
} HMRefreshControlState;

@interface HMRefreshControl ()
 //  记录当前滚动视图
@property (nonatomic,weak) UIScrollView *currentScrollView;

@property (nonatomic,assign) HMRefreshControlState hmState;

@property (nonatomic,strong) UIImageView *iconImageView;

@property (nonatomic,strong) UIActivityIndicatorView *indicatorView;

@property (nonatomic,strong) UILabel *messageLabel;
@end

@implementation HMRefreshControl

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    self.backgroundColor = [UIColor redColor];
    
    [self addSubview:self.iconImageView];
    [self addSubview:self.indicatorView];
    [self addSubview:self.messageLabel];
    
    
}

//  MARK: --    懒加载
//  下拉箭头
-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tableview_pull_refresh"]];
    }
    return _iconImageView;
}

//  风火轮
-(UIActivityIndicatorView *)indicatorView{
    if (_indicatorView == nil) {
        _indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    }
    return _indicatorView;
}

-(UILabel *)messageLabel{
    if (_messageLabel == nil) {
        _messageLabel = [[UILabel alloc] initWithTextColor:[UIColor darkGrayColor] fontSize:[UIFont systemFontOfSize:12]];
        _messageLabel.textAlignment = NSTextAlignmentCenter;
        _messageLabel.text = @"下拉刷新";
    }
    return _messageLabel;
}

@end
